package com.ruoyi.web.wuliu.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.wuliu.domain.CarSource;
import com.ruoyi.web.wuliu.service.ICarSourceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆发布Controller
 * 
 * @author ruoyi
 * @date 2023-12-05
 */
@RestController
@RequestMapping("/wuliu/source")
public class CarSourceController extends BaseController
{
    @Autowired
    private ICarSourceService carSourceService;

    /**
     * 查询车辆发布列表
     */
    @PreAuthorize("@ss.hasPermi('wuliu:source:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarSource carSource)
    {
        startPage();
        List<CarSource> list = carSourceService.selectCarSourceList(carSource);
        return getDataTable(list);
    }

    /**
     * 导出车辆发布列表
     */
    @PreAuthorize("@ss.hasPermi('wuliu:source:export')")
    @Log(title = "车辆发布", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarSource carSource)
    {
        List<CarSource> list = carSourceService.selectCarSourceList(carSource);
        ExcelUtil<CarSource> util = new ExcelUtil<CarSource>(CarSource.class);
        util.exportExcel(response, list, "车辆发布数据");
    }

    /**
     * 获取车辆发布详细信息
     */
    @PreAuthorize("@ss.hasPermi('wuliu:source:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(carSourceService.selectCarSourceById(id));
    }

    /**
     * 新增车辆发布
     */
    @PreAuthorize("@ss.hasPermi('wuliu:source:add')")
    @Log(title = "车辆发布", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarSource carSource)
    {
        return toAjax(carSourceService.insertCarSource(carSource));
    }

    /**
     * 修改车辆发布
     */
    @PreAuthorize("@ss.hasPermi('wuliu:source:edit')")
    @Log(title = "车辆发布", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarSource carSource)
    {
        return toAjax(carSourceService.updateCarSource(carSource));
    }

    /**
     * 删除车辆发布
     */
    @PreAuthorize("@ss.hasPermi('wuliu:source:remove')")
    @Log(title = "车辆发布", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(carSourceService.deleteCarSourceByIds(ids));
    }
}
